#region copyright
/*
* Copyright (c) 2008, Dion Kurczek
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the <organization> nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY DION KURCZEK ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL DION KURCZEK BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace SCG.TurboSprite
{
    public class ParticleExplosionSprite : Sprite
    {
        //public members
        public ParticleExplosionSprite(int particles, Color startColor, Color endColor, int startDiam, int endDiam, int lifeSpan)
        {
            if (startDiam > endDiam)
                endDiam = startDiam;
            StartColor = startColor;
            EndColor = endColor;
            StartDiameter = startDiam;
            EndDiameter = endDiam;
            LifeSpan = lifeSpan;
            _numParticles = particles;
            Shape = new RectangleF(-15, -15, 30, 30);
        }

        //properties
        public Color StartColor { get; set; }
        public Color EndColor { get; set; }
        public int StartDiameter { get; set; }
        public int EndDiameter { get; set; }
        public int LifeSpan { get; set; }

        //Decrement life
        public override void Process()
        {
            if (_numParticles > 0)
            {
                while (_numParticles > 0)
                {
                    ExplosionParticle p = CreateParticle();
                    _particles.Add(p);
                    _numParticles--;
                }
            }

            LifeSpan--;
            if (LifeSpan <= 0)
                Kill();
        }

        //Render the sprite
        public override void Render(Graphics g)
        {
            foreach (ExplosionParticle p in _particles)
            {
                p.Process();
                p.Render(g, Surface);
            }
        }

        //create the basic particle type
        public virtual ExplosionParticle CreateParticle()
        {
            return new ExplosionParticle(this);
        }

        //private members
        private int _numParticles = 0;
        private List<ExplosionParticle> _particles = new List<ExplosionParticle>();     
    }
}
